<%--
  作者: 小梁子
  创建时间: 2020/9/29 11:12
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>用户信息信息</h5>
                </div>
                <div class="ibox-content">
                    <div <%--style="float: left"--%>style="margin-left: 5%">
                        <button onclick="showEditModal()" type="button" class="btn btn-primary"
                        <%--                                                                  data-toggle="modal"--%>
                        <%--                                                                  data-target="#editModal"--%>>
                            <i class="fa fa-user-plus"></i>
                        </button>
                        <a onclick=" " href="" class="btn btn-primary "><i class="fa fa-refresh"></i></a>
                    </div>
                    <table class="table table-striped table-bordered table-hover " id=""
                           style="text-align: center;width: 90%;margin-left: 5%;margin-right: 5%">
                        <thead>
                        <tr>
                            <th style="width: 10%;text-align: center">用户ID</th>
                            <th style="width: 10%;text-align: center">用户名</th>
                            <th style="width: 15%;text-align: center">用户昵称</th>
                            <th style="width: 15%;text-align: center">用户角色</th>
                            <th style="width: 10%;text-align: center">用户状态</th>
                            <th style="width: 12%;text-align: center">操作</th>
                        </tr>
                        </thead>
                        <tbody class="table table-striped table-bordered table-hover" id="tb">

                        </tbody>

                    </table>
                    <div class="margin" style="margin-left: 5%">
                        每一页显示<select id="pageSizeSelect" onchange="onSelectChange()">
                        <option value="5">5</option>
                        <option value="10">10</option>
                        <option value="15">15</option>
                    </select> 条数据，
                        当前是第<span id="currentPageSpan"></span> 页，
                        总共<span id="totalPageSpan"></span> 页
                        <button class="button" onclick="firstPage()" id="firstPage">首页</button>
                        <button class="button" onclick="prePage()" id="prePage">上一页</button>
                        <button class="button" onclick="nextPage()" id="nextPage">下一页</button>
                        <button class="button" onclick="lastPage()" id="lastPage">尾页</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%--添加用户信息模态框--%>
<div class="modal inmodal" id="editModal">
    <%--对话模态框--%>
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">关闭</span>
                </button>
                <i class="fa fa-book modal-icon"></i>
                <h4 class="modal-title">添加用户信息</h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="userIdInput">
                <label class="control-label">用户昵称</label>
                <input class="form-control" type="text" id="userNicknameInput" placeholder="请输入用户昵称">
                <label class="control-label">用户名</label>
                <input class="form-control" type="text" id="userNameInput" placeholder="请输入用户名">
                <label class="control-label">用户密码</label>
                <input class="form-control" type="password" id="userPasswordInput" placeholder="请输入密码">
                <%--                以下存放用户角色信息下拉框，多级联动--%>
                <label class="control-label">请选择角色信息</label>
                <select class="form-control m-b" name="account" id="selt1">
                    <option selected="selected">请选择角色信息</option>
                    <option value="3">教务主任</option>
                    <option value="2">班主任</option>
                    <option value="1">任课教师</option>
                    <option value="4">管理员</option>
                    <%--               后期开发     <option id="studentSelect">学生</option>--%>
                </select>


                <%--                role部分--%>
                <%--    permission部分--%>
                <%--                舍弃掉--%>
                <%--                <label class="control-label">请选择角色权限模块</label>--%>
                <%--                <select class="form-control m-b" name="account" multiple="multiple" id="selt2">--%>
                <%--                </select>--%>
                <%--    单独的各自信息输入--%>
                <%-- 教师信息输入div--%>
                <div style="display:none" id="teacherDiv">
                    <label class="control-label">教师姓名</label>
                    <input class="form-control" type="text" id="teacherNameInput" placeholder="请输入教师姓名">
                    <label class="control-label">性别</label>
                    <div class="radio">
                        <label>
                            <input type="radio" checked="checked" value="1" id="teacherMan" name="sex">男</label>
                        <label>
                            <input type="radio" value="0" id="teacherWoman" name="sex">女</label>
                    </div>
                    <label class="control-label">可选课程</label>
                    <select class="form-control m-b" name="account" id="surplusCourse">
                    </select>
                    <%--                    <label class="control-label">课程ID</label>--%>
                    <%--                    <input class="form-control" type="text" id="courseIdInput" placeholder="请输入课程ID" maxlength="6"--%>
                    <%--                           value="0"--%>
                    <%--                           onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"--%>
                    <%--                           onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}">--%>

                    <label class="control-label">电话</label>
                    <input class="form-control" type="text" id="teacherPhoneInput" maxlength="11"
                           oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入教师电话">
                </div>

                <%-- 教务主任信息输入div--%>
                <div style="display:none" id="registrarDiv">
                    <label class="control-label">教务主任姓名</label>
                    <input class="form-control" type="text" id="registrarNameInput" placeholder="请输入教务主任姓名">
                    <label class="control-label">性别</label>
                    <div class="radio">
                        <label>
                            <input type="radio" checked="checked" value="1" id="registrarMan" name="sex">男</label>
                        <label>
                            <input type="radio" value="0" id="registrarWoman" name="sex">女</label>
                    </div>
                    <label class="control-label">专业ID</label>
                    <input class="form-control" type="text" id="departmentIdInput" placeholder="请输入专业ID" maxlength="6"
                           value="0"
                           onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                           onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}">

                    <label class="control-label">电话</label>
                    <input class="form-control" type="text" id="registrarPhoneInput" maxlength="11"
                           oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入教务主任电话">
                </div>

                <%-- 班主任信息输入div--%>
                <div style="display:none" id="headmasterDiv">
                    <label class="control-label">班主任姓名</label>
                    <input class="form-control" type="text" id="headmasterNameInput" placeholder="请输入班主任姓名">
                    <label class="control-label">性别</label>
                    <div class="radio">
                        <label>
                            <input type="radio" value="1" id="headmasterMan" name="sex">男</label>
                        <label>
                            <input type="radio" value="0" id="headmasterWoman" name="sex">女</label>
                    </div>
                    <label class="control-label">班级ID</label>
                    <input class="form-control" type="text" id="classIdInput" placeholder="请输入班级ID" maxlength="6"
                           value="0"
                           onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                           onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}">

                    <label class="control-label">电话</label>
                    <input class="form-control" type="text" id="headmasterPhoneInput" maxlength="11"
                           oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入班主任电话">
                </div>

            </div>
            <div class="modal-footer">
                <button class="button btn-primary" data-dismiss="modal">取消</button>
                <button class="button btn-primary" onclick="putFormAjax()">确定</button>
            </div>
        </div>
    </div>
</div>


<%--用户详情展示--%>
<div class="modal inmodal" id="editModal2">
    <%--对话模态框--%>
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">关闭</span>
                </button>
                <i class="fa fa-book modal-icon"></i>
                <h4 class="modal-title">用户详情信息</h4>
            </div>
            <div class="modal-body">

                <div id="infodiv">

                </div>
                <center><h3>权限信息</h3></center>
                <table class="table table-striped table-bordered table-hover " id=""
                       style="text-align: center;width: 90%;margin-left: 5%;margin-right: 5%">
                    <thead>
                    <tr>
                        <th style="width: 15%;text-align: center">权限模块</th>
                        <th style="width: 15%;text-align: center">url权限</th>
                    </tr>
                    </thead>
                    <tbody class="table table-striped table-bordered table-hover" id="userinfodiv">

                    </tbody>

                </table>
                <div id="infoShow">

                </div>
            </div>
            <div class="modal-footer" id="userInfoShowFoot">

            </div>
        </div>
    </div>
</div>


<%--修改用户模态框--%>
<div class="modal inmodal" id="editModalUserInfo">
    <%--对话模态框--%>
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">关闭</span>
                </button>
                <i class="fa fa-book modal-icon"></i>
                <h4 class="modal-title">修改用户信息</h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="userInfoId">
                <label class="control-label">用户昵称</label>
                <input class="form-control" type="text" id="userInfoNicknameInput">
                <label class="control-label">用户名</label>
                <input class="form-control" type="text" id="userInfoNameInput" disabled="disabled">
                <label class="control-label">新密码</label>
                <input class="form-control" type="password" id="new_password" name="new_password"
                       placeholder="输入新密码"/>
                <label class="control-label">确定新密码</label>
                <input class="form-control" type="password" id="confirm_password" name="confirm_password"
                       placeholder="确定新密码" onblur="cheakPassword()"/>


            </div>
            <div class="modal-footer">
                <button class="button btn-primary" data-dismiss="modal">取消</button>
                <button class="button btn-primary" onclick="editUserInfoAjax()" disabled="disabled" id="editUser">确定
                </button>
            </div>
        </div>
    </div>
</div>


<!-- 全局js -->
<script src="${pageContext.request.contextPath}/static/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js?v=3.3.6"></script>


<!-- Peity -->
<script src="${pageContext.request.contextPath}/static/js/plugins/peity/jquery.peity.min.js"></script>

<!-- 自定义js -->
<script src="${pageContext.request.contextPath}/static/js/content.js?v=1.0.0"></script>


<!-- iCheck -->
<script src="${pageContext.request.contextPath}/static/js/plugins/iCheck/icheck.min.js"></script>

<!-- Peity -->
<script src="${pageContext.request.contextPath}/static/js/demo/peity-demo.js"></script>
<script src="${pageContext.request.contextPath}/static/js/plugins/sweetalert/sweetalert.min.js"></script>
<link href="${pageContext.request.contextPath}/static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });
</script>
<script>
    <%--    分页功能--%>
    //当前页码
    var currentPage = 1;
    //每页展示多少条信息
    var pageSize = 5;
    //总页数
    var totalPage;

    //首页
    function firstPage() {
        currentPage = 1;
//加载页面
        allUserList();
    }

    //上一页
    function prePage() {
        currentPage--;
        if (currentPage < 1) {
            currentPage = 1;
        }
        //加载页面
        allUserList();
    }

    //下一页
    function nextPage() {
        currentPage++;
        if (currentPage > totalPage) {
            currentPage = totalPage;
        }
        //加载页面
        allUserList();
    }

    function onSelectChange() {
        pageSize = $("#pageSizeSelect").val();
        allUserList();
    }

    //尾页
    function lastPage() {
        currentPage = totalPage;
//加载页面
        allUserList();

    }

</script>
<%--ajax方式查询信息--%>
<script>
    <%--    用户添加的动态div展示--%>
    $(function () {

        $("#selt1").change(function () {
            //permission已经舍弃
            // $("#selt2").empty();
            // var permissionsList = [["基本信息", "课程管理", "学生管理", "教师管理", "院系管理"], ["基本信息", "课程管理", "学生管理", "教师管理"], ["基本信息", "课程管理", "学生管理"], ["基本信息", "用户管理",]];
            // var permission = permissionsList[$("#selt1 option:selected").val()];
            // $.each(permission, function (i, m) {
            //     $("#selt2").append("<option value=" + i + ">" + m + "</option>");
            // });
            var rolename = $("#selt1 option:selected").text();
            switch (rolename) {
                case "任课教师":
                    $('#teacherDiv').show();

                    $.ajax({
                        url: "${pageContext.request.contextPath}/user/getFreeCourseId",
                        type: "post",
                        dataType: "json",
                        contentType: "application/x-www-form-urlencoded",
                        success: function (result) {
                            if (result.code == 0) {
                                //自动在模态框中显示值
                                for (var x in result.surplusCourse) {
                                    $("#surplusCourse").append("<option value=" + result.surplusCourse[x].courseId + ">" + result.surplusCourse[x].courseName + "</option>");
                                }
                                $("#surplusCourse").val(result.teacher.courseId);

                            }
                        },
                        error: function (err) {
                            console.log(JSON.stringify(err));
                        }
                    });

                    $("#headmasterDiv").attr("style", "display:none;");
                    $("#registrarDiv").attr("style", "display:none;");
                    break;
                case "班主任":
                    $('#headmasterDiv').show();
                    $("#registrarDiv").attr("style", "display:none;");
                    $("#teacherDiv").attr("style", "display:none;");
                    break;
                case "教务主任":
                    $('#registrarDiv').show();
                    $("#teacherDiv").attr("style", "display:none;");
                    $("#headmasterDiv").attr("style", "display:none;");
                    break;
                case "管理员":
                    $('#registrarDiv').attr("style", "display:none;");
                    $("#teacherDiv").attr("style", "display:none;");
                    $("#headmasterDiv").attr("style", "display:none;");
                    break;
                case "学生":

                    break;
            }

        });

    });


    <%--    文档加载事件，查询用户列表--%>
    $(function () {
        allUserList();
    });


    function loadList(usersInfo) {
        var html = '';
        for (var i = 0; i < usersInfo.length; i++) {
            var item = usersInfo[i];
            html += "<tr>";
            html += "<td> " + item.userId + "</td>";
            html += "<td>" + item.userUserName + "</td>";
            html += "<td> " + item.userNickName + "</td>";
            html += "<td> " + item.roleName + "</td>";
            if (item.userDeleted == 1) {
                html += "<td>启用</td>";
            } else {
                html += "<td>停用</td>";
            }

            //用户的详细信息图标
            html += "<td><button class='btn btn-primary' onclick='getOneUserInfo(\"" + item.userId + "\")'><i class=\"fa fa-bars\"></i>" + "</button>" +
                //编辑用户信息的图标
                "<button class='btn btn-primary' onclick='getUserDetail(\"" + item.userId + "\")'><i class=\"fa fa-edit\"></i>" +
                "</button>" +
                //更改用户的状态
                "&nbsp<button onclick='ChangeUserDeleted(\"" + item.userId + "\"" + "," + "\"" + item.userDeleted + "\")' class='btn btn-primary'><i class=\"fa fa-bullseye\"></i></button></td>";
            html += "</tr>";
        }
        $("#tb").html(html);
    }

    //     ChangeUserDeleted(\"" + item.userId +","+item.userDeleted+ "\")
    // "abc(\""+item.userId+"\""+","+"\""+item.userDeleted+"\")"

    function allUserList() {
        $.ajax({

            url: "${pageContext.request.contextPath}/user/queryAllUsers",
            type: "get",
            data: {currentPage: currentPage, pageSize: pageSize},
            dataType: "json",
            success: function (result) {
                if (result.code == 0) {
                    loadList(result.userList);
                    totalPage = result.totalPage;
                    $("#totalPageSpan").html(totalPage);
                    $("#currentPageSpan").html(currentPage);
                }
            },
            error: function (err) {
                console.log("ajax错误！");
            }
        })
    }

    //获取当前行用户的详细信息并展示出来
    function getOneUserInfo(userId) {
        $.ajax({
            url: "${pageContext.request.contextPath}/user/getOneUserInfo",
            type: 'get',
            contentType: 'application/x-www-form-urlencoded',
            data: {
                userId: userId
            },
            dataType: 'json',
            success: function (result) {
                console.log(result);
                var role = result.role;
                var teacher = result.teacher;
                var headmaster = result.headmaster;
                var registrar = result.registrar;
                $("#user").val(role.name);
                permissionS(role);
                welcomeUser(role);
                switch (role.name) {
                    case "任课教师":
                        teacherInfo(teacher);
                        break;
                    case "班主任":
                        headmasterInfo(headmaster);
                        break;
                    case "教务主任":
                        registrarInfo(registrar);
                        break;
                    case "管理员":

                        break;
                    case "学生":

                        break;
                }
                $('#editModal2').modal('show');
                var html = "";
                html += " <button class=\"button btn-primary\" data-dismiss=\"modal\">取消</button>";
                html += "<button class=\"button btn-primary\" onclick=\"";
                html += "getUserDetail(";
                html += userId;
                html += ")\">编辑</button>";
                $("#userInfoShowFoot").html(html);

            },
            error: function (err) {
                console.log("ajax错误！");
            }
        })

    }

    //教务主任信息展示
    function registrarInfo(registrar) {
        var html = '';
        html += '<center><h3>教务主任信息</h3></center>';
        html += '<table class="table table-striped table-bordered table-hover " id=""style="text-align: center;width: 90%;margin-left: 5%;margin-right: 5%">\n' +
            '        <thead>\n' +
            '        <tr>';
        html += '<th style="width: 15%;text-align: center">属性</th>\n' +
            '        <th style="width: 15%;text-align: center">信息</th>\n' +
            '        </tr>\n' +
            '        </thead>';
        html += '<tbody class="table table-striped table-bordered table-hover" ">';
        html += "<tr><td>教务主任ID</td>";
        html += "<td>" + registrar.registrarId + "</td></tr>";
        html += "<tr><td>教务主任姓名</td>";
        html += "<td>" + registrar.registrarName + "</td></tr>";
        html += "<tr><td>教务主任性别</td>";
        if (registrar.registrarSex == 0) {
            html += "<td>女</td></tr>";
        } else {
            html += "<td>男</td></tr>";
        }
        html += "<tr><td>专业</td>";
        html += "<td>" + registrar.department.departmentName + "</td></tr>";
        html += "<tr><td>电话</td>";
        html += "<td>" + registrar.registrarPhone + "</td></tr>";
        html += "<tr><td>状态</td>";
        if (registrar.registrarDeleted == 0) {
            html += "<td>已删除</td></tr>";
        } else {
            html += "<td>正常</td></tr>";
        }
        html += '</tbody>';
        html += '</table>';
        $("#infoShow").html(html);
    }

    //班主任信息展示
    function headmasterInfo(headmaster) {
        var html = '';
        html += '<center><h3>班主任信息</h3></center>';
        html += '<table class="table table-striped table-bordered table-hover " id=""style="text-align: center;width: 90%;margin-left: 5%;margin-right: 5%">\n' +
            '        <thead>\n' +
            '        <tr>';
        html += '<th style="width: 15%;text-align: center">属性</th>\n' +
            '        <th style="width: 15%;text-align: center">信息</th>\n' +
            '        </tr>\n' +
            '        </thead>';
        html += '<tbody class="table table-striped table-bordered table-hover" ">';
        html += "<tr><td>班主任ID</td>";
        html += "<td>" + headmaster.headmasterId + "</td></tr>";
        html += "<tr><td>班主任姓名</td>";
        html += "<td>" + headmaster.headmasterName + "</td></tr>";
        html += "<tr><td>班主任性别</td>";
        if (headmaster.headmasterSex == 0) {
            html += "<td>女</td></tr>";
        } else {
            html += "<td>男</td></tr>";
        }
        html += "<tr><td>班级ID</td>";
        html += "<td>" + headmaster.classId + "</td></tr>";
        html += "<tr><td>电话</td>";
        html += "<td>" + headmaster.headmasterPhone + "</td></tr>";
        html += "<tr><td>状态</td>";
        if (headmaster.headmasterDeleted == 0) {
            html += "<td>已删除</td></tr>";
        } else {
            html += "<td>正常</td></tr>";
        }

        html += '</tbody>';
        html += '</table>';
        $("#infoShow").html(html);


    }

    //    老师信息展示
    function teacherInfo(teacher) {
        var html = '';
        html += '<center><h3>任课教师信息</h3></center>';
        html += '<table class="table table-striped table-bordered table-hover " id=""style="text-align: center;width: 90%;margin-left: 5%;margin-right: 5%">\n' +
            '        <thead>\n' +
            '        <tr>';
        html += '<th style="width: 15%;text-align: center">属性</th>\n' +
            '        <th style="width: 15%;text-align: center">信息</th>\n' +
            '        </tr>\n' +
            '        </thead>';
        html += '<tbody class="table table-striped table-bordered table-hover" ">';
        html += "<tr><td>教师ID</td>";
        html += "<td>" + teacher.teacherId + "</td></tr>";
        html += "<tr><td>教师姓名</td>";
        html += "<td>" + teacher.teacherName + "</td></tr>";
        html += "<tr><td>教师性别</td>";
        if (teacher.teacherSex == 0) {
            html += "<td>女</td></tr>";
        } else {
            html += "<td>男</td></tr>";
        }
        html += "<tr><td>课程ID</td>";
        html += "<td>" + teacher.courseId + "</td></tr>";
        html += "<tr><td>电话</td>";
        html += "<td>" + teacher.teacherPhone + "</td></tr>";
        html += "<tr><td>状态</td>";
        if (teacher.teacherDeleted == 0) {
            html += "<td>已删除</td></tr>";
        } else {
            html += "<td>正常</td></tr>";
        }
        html += '</tbody>';
        html += '</table>';
        $("#infoShow").html(html);
    }

    function permissionS(role) {
        var html = '';
        $("#infoShow").html(html);
        for (var i = 0; i < role.permissions.length; i++) {
            var item = role.permissions[i];
            html += "<tr>";
            html += "<td> " + item.name + "</td>";
            html += "<td>" + item.url + "</td>";
            html += "</tr>";
        }
        $("#userinfodiv").html(html);
    }

    function welcomeUser(role) {
        var html = '';
        $("#infodiv").html(html);
        html += '<center><h4>欢迎你！</h4>';
        html += '你是尊贵的';
        html += role.name;
        html += '</center><br>';
        $("#infodiv").html(html);
    }


    //    添加用户

    function putFormAjax() {
        //获取信息
        //user信息
        //userid
        var userId = $("#userIdInput").val();
        //用户昵称
        var userNickname = $("#userNicknameInput").val();
        //用户名
        var userName = $("#userNameInput").val();
        //用户密码
        var userPassword = $("#userPasswordInput").val();
        //role信息
        //角色姓名
        var roleName = $("#selt1 option:selected").text();
        var roleId = $("#selt1 option:selected").val();
        //权限模块  舍弃
        // var permissions = $("#selt2").val().toString();


        //教师信息获取
        //教师姓名
        var teacherName = $("#teacherNameInput").val();
        //获取对应的性别
        var teacherSex = $("#teacherDiv input:radio").val();
        //获取课程ID
        var courseId = $("#surplusCourse option:selected").val();
        //获取老师电话
        var teacherPhone = $("#teacherPhoneInput").val();


        //教务主任信息获取
        //姓名
        var registrarName = $("#registrarNameInput").val();
        //获取对应的性别
        var registrarSex = $("#registrarDiv input:radio").val();
        //获取专业id
        var departmentId = $("#departmentIdInput").val();
        //获取教务主任电话
        var registrarPhone = $("#registrarPhoneInput").val();


        //班主任信息获取
        //班主任姓名
        var headmasterName = $("#headmasterNameInput").val();
        //获取对应的性别
        var headmasterSex = $("#headmasterDiv input:radio").val();
        //获取专业id
        var classId = $("#classIdInput").val();
        //获取教务主任电话
        var headmasterPhone = $("#headmasterPhoneInput").val();


        //将数据封装到datavalu中
        var dataValue = {
            //user数据
            // userId:userId,
            userUserName: userName,
            userPassword: userPassword,
            userNickName: userNickname,
            //role信息
            name: roleName,
            roleId: roleId,
            //permission信息     舍弃
            // permissionsList:permissions,
            // 任课老师数据
            teacherName: teacherName,
            teacherSex: teacherSex,
            courseId: courseId,
            teacherPhone: teacherPhone,
            //班主任数据
            headmasterName: headmasterName,
            classId: classId,
            headmasterPhone: headmasterPhone,
            headmasterSex: headmasterSex,
            //教务主任数据
            registrarName: registrarName,
            registrarSex: registrarSex,
            departmentId: departmentId,
            registrarPhone: registrarPhone
        };

        //ajax将数据传输到后台去
        $.ajax({
            url: "${pageContext.request.contextPath}/user/edit",
            type: 'post',
            // traditional:true,//这使json格式的字符不会被转码
            contentType: 'application/x-www-form-urlencoded',
            data: dataValue,
            dataType: 'json',
            success: function (result) {
                if (result.code == 1) {
                    swal({
                        title: "用户添加成功！",
                        text: "来自专业20年CV攻城狮的温馨提醒"
                    });
                    $("#editModal").modal("hide");
                    window.location.reload();
                } else {
                    swal({
                        title: "添加失败，请重试",
                        text: "来自专业20年CV攻城狮的温馨提醒"
                    });
                }
            },
            error: function (err) {
                console.log(err);
            }
        })


    }

    //改变用户状态
    function ChangeUserDeleted(userId, userDeleted) {
        if (userDeleted == 1) {
            swal({
                    title: "您确定要修改状态吗！",
                    text: "停用后，账户将无法使用，请谨慎操作！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的，我要停用！",
                    cancelButtonText: "让我再考虑一下…",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function (isConfirm) {
                    if (isConfirm) {
                        var dataValue = {
                            userId: userId,
                            userDeleted: 0
                        };
                        changeAjax(dataValue);
                        swal("停用成功！", "您已经停用了这个账户。", "success");
                    } else {
                        swal("已取消", "您取消了停用操作！", "error");
                    }
                });
        } else {
            swal({
                    title: "您确定要修改状态吗！",
                    text: "启用后，账户将继续使用，请谨慎操作！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的，我要启用！",
                    cancelButtonText: "让我再考虑一下…",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function (isConfirm) {
                    if (isConfirm) {
                        var dataValue = {
                            userId: userId,
                            userDeleted: 1
                        };
                        changeAjax(dataValue);
                        swal("启用成功！", "您已经启用了这个账户。", "success");
                    } else {
                        swal("已取消", "您取消了启用操作！", "error");
                    }
                });

        }
    }

    function changeAjax(dataValue) {
        //后台修改deleted为0，根据userID
        $.ajax({
            url: "${pageContext.request.contextPath}/user/changeDeleted",
            type: 'post',
            contentType: 'application/x-www-form-urlencoded',
            data: dataValue,
            dataType: 'json',
            success: function (result) {
                if (result.code == 1) {
                    window.location.reload();
                }
            },
            error: function (err) {
                console.log(err);
            }
        });

    }

    function cheakPassword() {
        var password = $("#new_password").val();
        var confirm_password = $("#confirm_password").val();
        if (password == confirm_password) {
            $("#editUser").attr("disabled", false);
        } else {
            alert("两次密码不一致，请重试");
            $("#new_password").val("");
            $("#confirm_password").val("");
        }

    }

    function getUserDetail(userId) {
        $("#editModal2").modal("hide");
        $("#userInfoId").val(userId);
        $("#new_password").val("");
        $("#confirm_password").val("");
        $.ajax({
            url: "${pageContext.request.contextPath}/user/getUserInfoByUserId",
            type: 'post',
            contentType: 'application/x-www-form-urlencoded',
            data: {
                userId: userId
            },
            dataType: 'json',
            success: function (result) {
                $("#userInfoNicknameInput").val(result.user.userNickName);
                $("#userInfoNameInput").val(result.user.userUserName);
                $("#userInfoId").val(result.user.userId);
            },
            error: function (err) {
                console.log(err);
            }
        });

        $('#editModalUserInfo').modal('show');
    }

    function editUserInfoAjax() {
        var userNickName = $("#userInfoNicknameInput").val();
        var userUserName = $("#userInfoNameInput").val();
        var userId = $("#userInfoId").val();
        var userPassword = $("#confirm_password").val();

        $.ajax({
            url: "${pageContext.request.contextPath}/user/editUserInfoAjax",
            type: 'post',
            contentType: 'application/x-www-form-urlencoded',
            data: {
                userId: userId,
                userNickName: userNickName,
                userUserName: userUserName,
                userPassword: userPassword
            },
            dataType: 'json',
            success: function (result) {
                if (result.code == 1) {
                    swal({
                        title: "用户信息修改成功！",
                        text: "来自专业20年CV攻城狮的温馨提醒"
                    });
                    $("#editModalUserInfo").modal("hide");
                    window.location.reload();
                } else {
                    swal({
                        title: "修改失败，请重试",
                        text: "来自专业20年CV攻城狮的温馨提醒"
                    });
                }
            },
            error: function (err) {
                console.log(err);
            }
        });

    }

    function showEditModal() {
        $('#headmasterDiv').attr("style", "display:none;");
        $("#registrarDiv").attr("style", "display:none;");
        $("#teacherDiv").attr("style", "display:none;");
        $("#userNicknameInput").val('');
        $("#userNameInput").val('');
        $("#userPasswordInput").val('');
        $("#teacherNameInput").val('');
        $("#teacherPhoneInput").val('');
        $("#registrarNameInput").val('');
        $("#departmentIdInput").val(0);
        $("#registrarPhoneInput").val('');
        $("#headmasterNameInput").val('');
        $("#classIdInput").val(0);
        $("#headmasterPhoneInput").val('');
        $("#editModal").modal("show");
    }
</script>
</body>
</html>
